﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

/// <summary>
/// Summary description for clsJobPostDAL
/// </summary>
public class clsJobPostDAL
{

    InstantNaukriDataContextDataContext objInstantNaukriDataContextDataContext = new InstantNaukriDataContextDataContext();
    public clsJobPostDAL()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public List<IN_TB_JOB_POST> GetAllJobPost()
    {
        try
        {
            List<IN_TB_JOB_POST> objIN_TB_JOB_POST = new List<IN_TB_JOB_POST>();
            objIN_TB_JOB_POST = (from obj in objInstantNaukriDataContextDataContext.IN_TB_JOB_POSTs
                                 select obj).ToList();
            return objIN_TB_JOB_POST;
        }
        catch (Exception)
        {

            throw;
        }
    }

    public List<IN_TB_JOB_POST> GetJobPostByEmployerId(int EmployerId)
    {
        try
        {
            List<IN_TB_JOB_POST> objIN_TB_JOB_POST = new List<IN_TB_JOB_POST>();
            objIN_TB_JOB_POST = (from obj in objInstantNaukriDataContextDataContext.IN_TB_JOB_POSTs
                                 where obj.EMPLOYER_ID == EmployerId
                                 orderby obj.CREATED_ON descending
                                 select obj).ToList();
            return objIN_TB_JOB_POST;
        }
        catch (Exception)
        {

            throw;
        }
    }

    public IN_TB_JOB_POST GetJobPostById(int ID)
    {
        try
        {
            IN_TB_JOB_POST objIN_TB_JOB_POST = new IN_TB_JOB_POST();
            objIN_TB_JOB_POST = (from obj in objInstantNaukriDataContextDataContext.IN_TB_JOB_POSTs
                                 where obj.ID == ID
                                 select obj).SingleOrDefault();
            return objIN_TB_JOB_POST;
        }
        catch (Exception)
        {

            throw;
        }
    }


    public int SaveJobPost(IN_TB_JOB_POST objIN_TB_JOB_POST)
    {
        try
        {
            IN_TB_JOB_POST objIN_TB_JOB_POSTD = new IN_TB_JOB_POST();
            objIN_TB_JOB_POSTD = (from obj in objInstantNaukriDataContextDataContext.IN_TB_JOB_POSTs
                                  where obj.ID == objIN_TB_JOB_POST.ID
                                  select obj).SingleOrDefault();
            if (objIN_TB_JOB_POSTD != null)
            {
                objIN_TB_JOB_POSTD.ID = objIN_TB_JOB_POST.ID;
                objIN_TB_JOB_POSTD.JOB_TITLE = objIN_TB_JOB_POST.JOB_TITLE;
                objIN_TB_JOB_POSTD.SKILLS_REQUIRED = objIN_TB_JOB_POST.SKILLS_REQUIRED;
                objIN_TB_JOB_POSTD.MIN_EXPERIENCE_REQUIRED = objIN_TB_JOB_POST.MIN_EXPERIENCE_REQUIRED;
                objIN_TB_JOB_POSTD.MAX_EXPERIENCE_REQUIRED = objIN_TB_JOB_POST.MAX_EXPERIENCE_REQUIRED;
                objIN_TB_JOB_POSTD.JOB_LOCATION = objIN_TB_JOB_POST.JOB_LOCATION;
                objIN_TB_JOB_POSTD.JOB_DESCRIPTION = objIN_TB_JOB_POST.JOB_DESCRIPTION;
                objIN_TB_JOB_POSTD.QUALIFICATION_REQUIRED = objIN_TB_JOB_POST.QUALIFICATION_REQUIRED;
                objIN_TB_JOB_POSTD.SALARY_OFFERED = objIN_TB_JOB_POST.SALARY_OFFERED;
                objIN_TB_JOB_POSTD.FUNCTIONAL_AREA = objIN_TB_JOB_POST.FUNCTIONAL_AREA;
                objIN_TB_JOB_POSTD.EMPLOYER_ID = objIN_TB_JOB_POST.EMPLOYER_ID;
                objIN_TB_JOB_POSTD.STATUS = objIN_TB_JOB_POST.STATUS;
                objIN_TB_JOB_POSTD.CREATED_BY = objIN_TB_JOB_POST.CREATED_BY;
                objIN_TB_JOB_POSTD.CREATED_ON = objIN_TB_JOB_POST.CREATED_ON;
                objIN_TB_JOB_POSTD.MODIFIED_BY = objIN_TB_JOB_POST.MODIFIED_BY;
                objIN_TB_JOB_POSTD.MODIFIED_ON = objIN_TB_JOB_POST.MODIFIED_ON;
                objInstantNaukriDataContextDataContext.SubmitChanges();
                return objIN_TB_JOB_POSTD.ID;
            }
            else
            {
                objInstantNaukriDataContextDataContext.IN_TB_JOB_POSTs.InsertOnSubmit(objIN_TB_JOB_POST);
                objInstantNaukriDataContextDataContext.SubmitChanges();
                return objIN_TB_JOB_POST.ID;
            }
        }
        catch (Exception)
        {

            throw;
        }
    }
}
